<script setup lang="ts">
import { getOtherAwardDetail } from "@/api/research/award";
import { FileUpload } from "@/components/common/FileUpload";
import { formatDate, isCanPreview } from "@/utils/common";
import { ref, watch } from "vue";
import { FormProps } from "../utils/types";

const props = withDefaults(defineProps<FormProps>(), {
  formInline: () => ({
    id: null,
    title: "新增",
    obtainRewardAchievementName: "",
    obtainRewardUnit: "",
    obtainRewardLevel: "",
    rewardName: "",
    rewardUnit: "",
    rewardLevel: "",
    obtainDate: "",
    obtainRewardName: "",
    score: 0,
    examineStatus: 0,
    examineDesc: ""
  }),
  dataId: null,
  userList: null
});

watch(
  () => props.dataId,
  async newValue => {
    if (!newValue) {
      return;
    }
    getOtherAwardDetail({ id: newValue }).then(res => {
      newFormInline.value = res.data;
    });
  },
  { immediate: true }
);

const ruleFormRef = ref();
const newFormInline = ref(props.formInline);

function getRef() {
  return ruleFormRef.value;
}

defineExpose({ getRef });
</script>

<template>
  <el-form
    ref="ruleFormRef"
    :model="newFormInline"
    label-width="160px"
    class="mr-12"
  >
    <el-form-item label="奖项名称" prop="obtainRewardAchievementName">
      <div>{{ newFormInline.obtainRewardAchievementName || "--" }}</div>
    </el-form-item>
    <el-form-item label="获奖级别" prop="rewardLevel">
      <div>{{ newFormInline.rewardLevel || "--" }}</div>
    </el-form-item>
    <el-form-item label="获奖人员" prop="obtainRewardName">
      <div>
        {{ newFormInline.obtainRewardName || "--" }}
      </div>
    </el-form-item>
    <el-form-item label="获奖单位" prop="obtainRewardUnit">
      <div>
        {{ newFormInline.obtainRewardUnit || "--" }}
      </div>
    </el-form-item>
    <el-form-item label="获奖等级" prop="obtainRewardLevel">
      <div>
        {{ newFormInline.obtainRewardLevel || "--" }}
      </div>
    </el-form-item>
    <el-form-item label="授奖单位" prop="rewardUnit">
      <div>{{ newFormInline.rewardUnit || "--" }}</div>
    </el-form-item>
    <el-form-item label="获奖日期" prop="obtainDate">
      <div>
        {{ formatDate(newFormInline.obtainDate) }}
      </div>
    </el-form-item>

    <el-form-item label="获取积分" prop="score">
      <div>{{ newFormInline.score || "--" }}</div>
    </el-form-item>
    <el-form-item label="证书" prop="additionalFile">
      <FileUpload
        v-model="newFormInline.additionalFile"
        :isCanPreview="isCanPreview(newFormInline, props.dataId)"
        disabled
      />
    </el-form-item>
    <el-form-item label="审核状态" prop="score">
      <el-tag v-if="newFormInline.examineStatus === 0" type="warning"
        >审核中</el-tag
      >
      <el-tag v-else-if="newFormInline.examineStatus === 1" type="primary"
        >已审核</el-tag
      >
      <el-tag v-else type="danger">已驳回</el-tag>
    </el-form-item>
    <el-form-item label="驳回原因" prop="score">
      <div>{{ newFormInline.examineDesc || "--" }}</div>
    </el-form-item>
  </el-form>
</template>
